// /*
//  * @Author: WanYiMing
//  * @Date:2024-02-05-11:24
//  * @Description:
//  */

using UnityEngine;

namespace Code.Utility
{
    public static class GameObjectUtils
    {
        public static T CheckComponent<T>(GameObject checkGameObject) where T : Component
        {
            T component = null;

            // 尝试获取已存在的组件
            if (checkGameObject.TryGetComponent<T>(out component))
            {
                return component;
            }
            else
            {
                // 添加组件并返回新添加的组件
                return checkGameObject.AddComponent<T>();
            }
        }
        
    }
}